//
//  MYNewFeatureViewCell.swift
//  MYWeiBo
//
//  Created by apple on 16/5/14.
//  Copyright © 2016年 YanMo. All rights reserved.
//

import UIKit

class MYNewFeatureViewCell: UICollectionViewCell {
    
    // 通过index页数来给背景设置不同的图片
    var index: Int = 0 {
        didSet{
//            MYPrint(items: "index:\(index)")
            bkgImaageView.image = UIImage(named:"new_feature_\(index + 1)")
            startButton.hidden = true
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
     private func prepareUI(){
        //往contenview中加内容
        contentView.addSubview(bkgImaageView)
        contentView.addSubview(startButton)
        
        //约束
        bkgImaageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(self.contentView)
        }
        
        startButton.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(self.contentView).offset(-140)
            make.centerX.equalTo(self.contentView)
        }
 
    }
    /**
     *开始动画
     */
    func startAnimation(){
        //开按钮大小比例变成0
        startButton.hidden = false
        startButton.transform = CGAffineTransformMakeScale(0, 0)
        UIView.animateWithDuration(1, delay: 0.3, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
                self.startButton.transform = CGAffineTransformIdentity
            }, completion: nil)
    
    }
    //开始的按钮的点击事件
    func startButtonClick(){
        //切换到主控制器
        let appdelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
        appdelegate.switchRootViewController(MYWelcomeViewController())
    }

    /**
    *  懒加载
    */
    private lazy var bkgImaageView:UIImageView = UIImageView(image: UIImage(named: "new_feature_1"))
    private lazy var startButton:UIButton = {
        let  button = UIButton()
        button.setTitle("开始体验", forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: UIControlState.Highlighted)
        button.hidden = true
        //添加点击事件
        button.addTarget(self, action: "startButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
  
}



















